#include "Object.h"

Object::Object() :m_objectId(0), m_posIdx(-1), m_count(0), m_canSeenId(0), m_type(CollectData_Type_None), m_pObjectCfg(nullptr)
{
	m_creatureKind = CREATURE_OBJECT;
	m_sightRange = 4000;
}

bool Object::UnInit()
{
	Creature::UnInit();
	return true;
}

void Object::Update(uint64_t tick)
{
	Creature::Update(tick);
}

void Object::GetVisibleDataToClient(CreaturesCreateData& cvData)
{
	CreaturesCreateData::Object *protoObject = cvData.add_objects();
	if (nullptr != protoObject)
	{
		protoObject->set_objectcid(m_Cid);
		protoObject->set_objectid(m_objectId);
		//protoObject->set_objecttype(m_type);
		protoObject->set_posx(m_pos.x);
		protoObject->set_posy(m_pos.y);
		protoObject->set_posz(m_pos.z);
		protoObject->set_count(m_count);
	}
}

bool Object::Born(CharIDType nObjectCid, uint32_t nObjectId, uint32_t sceneId, Point3<float>& bornPos, int32_t posIdx)
{
	m_pObjectCfg = g_GetThingCollectCfgTable()->GetThingCollectCfgInfo(nObjectId);
	if (nullptr == m_pObjectCfg)
	{
		LogErrFmtPrint("[logic] Object::Born...nullptr == m_pObjectCfg...objectId:%u ", nObjectId);
		return false;
	}

	m_Cid = nObjectCid;
	m_objectId = nObjectId;
	m_posIdx = posIdx;
	m_count = m_pObjectCfg->collectTimes;
	m_type = (CollectData_Type)m_pObjectCfg->type;
	STransParam transParam;
	transParam.transType = ETransType_Born;
	if (!EnterScene(sceneId, bornPos, transParam))
	{
		m_Cid = 0;
		m_objectId = 0;
		m_posIdx = 0;
		m_pObjectCfg = nullptr;
		return false;
	}
	return true;
}

bool Object::PlayerCanSeen(CharIDType charId)
{
	if (m_canSeenId <= 0 || m_canSeenId == charId)
	{
		return true;
	}
	return false;
}

void Object::SetCount(uint32_t count)
{
	m_count = count;
	CollectFishBroadcast broadcast;
	broadcast.set_fish_cid(m_Cid);
	broadcast.set_times(m_count);
	BroadCastData(EMOUDLE_ID_COLLECT, LOGIC_TO_CLIENT_COLLECT_FISH_BROADCAST, (ProtoBufBase*)&broadcast);
}
